package com.fand.stater.handler;

import java.util.Date;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.fand.stater.context.UserInfoThreadLocal;
import org.apache.ibatis.reflection.MetaObject;

public class CommonMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createdTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "status", Integer.class, Integer.valueOf("0"));
        this.strictInsertFill(metaObject, "createdBy", Long.class, UserInfoThreadLocal.get().getId());
        this.strictInsertFill(metaObject, "updatedBy", Long.class, UserInfoThreadLocal.get().getId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updatedBy", Long.class, UserInfoThreadLocal.get().getId());

    }
}
